package cn.e3mall.item.controller;

import cn.e3mall.item.pojo.Item;
import cn.e3mall.pojo.TbItem;
import cn.e3mall.pojo.TbItemDesc;
import cn.e3mall.service.ItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class ItemController {

    @Autowired
    private ItemService itemService;



    @RequestMapping("/item/{itemId}")
    public String showItemInfo(@PathVariable String itemId, Model model){
        TbItem tbItem = itemService.getItemById(Long.parseLong(itemId));
        TbItemDesc itemDesc = itemService.getItemDescById(Long.parseLong(itemId));
        Item item = new Item(tbItem);

        model.addAttribute("item",item);
        model.addAttribute("itemDesc",itemDesc);

        return "item";
    }

}
